using System.Collections;
using TMPro;
using UnityEngine;

public class IntroDisclaimer : MonoBehaviour
{
	[SerializeField]
	private TextMeshPro DisclaimerText;

	[SerializeField]
	private AudioClip DenySFX;

	[SerializeField]
	private AudioClip ConfirmSFX;

	[SerializeField]
	private AudioClip FinishConfirmSFX;

	[SerializeField]
	private AudioClip StaticSFX;

	private string originalDisclaimerText;

	private int remainingConfirmPresses = 3;

	private bool canBeginConfirming;

	private void Start()
	{
		originalDisclaimerText = DisclaimerText.text;
		DisclaimerText.text = originalDisclaimerText;
		if (PlayerPrefs.GetInt("Setting_DyslexicText", 0) == 1)
		{
			DisclaimerText.font = SettingsManager.Instance.DyslexicFont;
			DisclaimerText.extraPadding = false;
		}
		MusicManager.PlaySong(StaticSFX, FadePreviousSong: true, 1f);
		StartCoroutine(Disclaimer());
	}

	private void Update()
	{
		if (canBeginConfirming)
		{
			if (Input.GetKeyDown(PlayerInput.Instance.Key_Confirm) && remainingConfirmPresses > 0)
			{
				CutsceneUtils.PlaySound(ConfirmSFX, CutsceneUtils.DRH_MixerChannels.Effect, 0.5f);
				remainingConfirmPresses--;
				DisclaimerText.text = originalDisclaimerText + $"\n请再按 <color=yellow>{remainingConfirmPresses}</color> 次 <color=yellow>{PlayerInput.Instance.Key_Confirm}</color> 键继续。";
			}
			else
			{
				DisclaimerText.text = originalDisclaimerText + $"\n请再按 <color=yellow>{remainingConfirmPresses}</color> 次 <color=yellow>{PlayerInput.Instance.Key_Confirm}</color> 键继续。";
			}
		}
	}

	private IEnumerator Disclaimer()
	{
		yield return new WaitForSeconds(1f);
		CutsceneUtils.PlaySound(DenySFX, CutsceneUtils.DRH_MixerChannels.Effect, 0.7f);
		CutsceneUtils.FadeInText3D(DisclaimerText, 0.5f);
		yield return new WaitForSeconds(1.5f);
		canBeginConfirming = true;
		while (remainingConfirmPresses > 0)
		{
			yield return null;
		}
		CutsceneUtils.PlaySound(FinishConfirmSFX, CutsceneUtils.DRH_MixerChannels.Effect, 0.5f);
		CutsceneUtils.FadeOutText3D(DisclaimerText);
		yield return new WaitForSeconds(0.5f);
		MusicManager.StopSong(Fade: true, 1f);
		if (PlayerPrefs.GetInt("NewDisclaimerViewed", 0) == 0)
		{
			UI_FADE.Instance.StartFadeIn(53, 1f);
		}
		else
		{
			UI_FADE.Instance.StartFadeIn(2, 1f);
		}
	}
}
